<template>
  <div :class="['page-header', layout, pageWidth]" :style="getBgClass">
    <div class="page-header-wide">
      <div class="breadcrumb">
        <a-breadcrumb>
          <a-breadcrumb-item :key="index" v-for="(item, index) in breadcrumb">
            <span>{{ item }}</span>
          </a-breadcrumb-item>
        </a-breadcrumb>
      </div>
      <div class="detail">
        <div class="main">
          <div class="row row1">
            <a-icon
              v-if="isHaveBack"
              type="left"
              style="color:#fff;font-size:22px;font-weight:bold"
              @click="$router.back()"
            />
            <h1 v-if="showPageTitle && title" class="title">{{ title }}</h1>
            <div class="action"><slot name="action"></slot></div>
          </div>
          <div class="row row2">{{ subTitle }}</div>
          <div class="row">
            <div v-if="this.$slots.content" class="content">
              <div v-if="avatar" class="avatar">
                <a-avatar :src="avatar" :size="72" />
              </div>
              <slot name="content"></slot>
            </div>
            <div v-if="this.$slots.extra" class="extra">
              <slot name="extra"></slot>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "PageHeader",
  props: {
    title: {
      type: [String, Boolean],
      required: false
    },
    subTitle: {
      type: String,
      required: false
    },
    breadcrumb: {
      type: Array,
      required: false
    },
    logo: {
      type: String,
      required: false
    },
    avatar: {
      type: String,
      required: false
    },
    headerImg: {
      type: String,
      required: false
    }
  },
  data() {
    return {};
  },
  computed: {
    ...mapState("setting", ["layout", "showPageTitle", "pageWidth"]),
    getBgClass() {
      console.log(this.$route);
      return {
        'background-image':
          "url(" +
          require("@/assets/img/" + this.$route.meta.bgImg + "") +
          ") !important"
      };
    },
    isHaveBack() {
      return this.$route.meta.haveBack;
    }
  }
};
</script>

<style lang="less" scoped>
@import "index";
.row1 {
  justify-content: flex-start !important;
  align-items: center;
  i {
    margin-right: 10px;
  }
  .title {
    margin-bottom: 0 !important;
  }
}
.row2 {
  margin-top: 20px;
  color: #fff;
  font-size: 13px;
}
</style>
